package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysClientRobot;
import com.ruoyi.system.service.ISysClientRobotService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户机器人Controller
 * 
 * @author ruoyi
 * @date 2023-12-26
 */
@RestController
@Api("用户-机器人管理")
@RequestMapping("/system/robot")
public class SysClientRobotController extends BaseController
{
    @Autowired
    private ISysClientRobotService sysClientRobotService;

    /**
     * 查询用户机器人列表
     */
    @PreAuthorize("@ss.hasPermi('system:robot:list')")
    @GetMapping("/list")
    @ApiOperation("查询用户机器人列表")
    public TableDataInfo list(SysClientRobot sysClientRobot)
    {
        startPage();
        List<SysClientRobot> list = sysClientRobotService.selectSysClientRobotList(sysClientRobot);
        return getDataTable(list);
    }

    /**
     * 导出用户机器人列表
     */
    @PreAuthorize("@ss.hasPermi('system:robot:export')")
    @Log(title = "用户机器人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出用户机器人列表")
    public void export(HttpServletResponse response, SysClientRobot sysClientRobot)
    {
        List<SysClientRobot> list = sysClientRobotService.selectSysClientRobotList(sysClientRobot);
        ExcelUtil<SysClientRobot> util = new ExcelUtil<SysClientRobot>(SysClientRobot.class);
        util.exportExcel(response, list, "用户机器人数据");
    }

    /**
     * 获取用户机器人详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:robot:query')")
    @GetMapping(value = "/{robotId}")
    @ApiOperation("获取用户机器人详细信息")
    public AjaxResult getInfo(@PathVariable("robotId") Long robotId)
    {
        return success(sysClientRobotService.selectSysClientRobotByRobotId(robotId));
    }

    /**
     * 新增用户机器人
     */
    @PreAuthorize("@ss.hasPermi('system:robot:add')")
    @Log(title = "用户机器人", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增用户机器人")
    public AjaxResult add(@RequestBody SysClientRobot sysClientRobot)
    {
        return toAjax(sysClientRobotService.insertSysClientRobot(sysClientRobot));
    }

    /**
     * 修改用户机器人
     */
    @PreAuthorize("@ss.hasPermi('system:robot:edit')")
    @Log(title = "用户机器人", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改用户机器人")
    public AjaxResult edit(@RequestBody SysClientRobot sysClientRobot)
    {
        return toAjax(sysClientRobotService.updateSysClientRobot(sysClientRobot));
    }

    /**
     * 删除用户机器人
     */
    @PreAuthorize("@ss.hasPermi('system:robot:remove')")
    @Log(title = "用户机器人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{robotIds}")
    @ApiOperation("删除用户机器人")
    public AjaxResult remove(@PathVariable Long[] robotIds)
    {
        return toAjax(sysClientRobotService.deleteSysClientRobotByRobotIds(robotIds));
    }
}
